package com.sskj.qiangjin.util;

import android.text.TextUtils;

import java.util.regex.Pattern;

public class HideUtil {
    /**
     * 获取到处理的手机号 152××××4012
     *
     * @param mobile
     * @return
     */
    public static String getPhoneHide(String mobile) {
        if (TextUtils.isEmpty(mobile)) {
            return "";
        }
        return mobile.substring(0, 3) + "****" + mobile.substring(7, 11);
    }

    /**
     * 获取到处理的身份证号 412824××××××××4753
     *
     * @param idCard
     * @return
     */
    public static String getIDCardHide(String idCard) {
        if (TextUtils.isEmpty(idCard)) {
            return "";
        }
        if (idCard.length() != 18) {
            return idCard;
        }
        return idCard.substring(0, 2) + "**************" + idCard.substring(16, 18);
    }

    /**
     * 邮箱**
     */

    public static String getEmailHide(String email) {
        if (TextUtils.isEmpty(email)) {
            return "";
        }
        String returnEmail = "";
        String emailStart = email.split("@")[0];
        if (emailStart.length() <= 4) {
            returnEmail = "**@" + email.split("@")[1];
        } else {
            returnEmail = emailStart.substring(0, 2) + "**" + emailStart.substring(emailStart.length() - 2, emailStart.length()) + "@" + email.split("@")[1];
        }
        return returnEmail;
    }

    /**
     * 判断是否为整数
     *
     * @param str 传入的字符串
     * @return 是整数返回true, 否则返回false
     */
    public static boolean isInteger(String str) {
        Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
        return pattern.matcher(str).matches();
    }

}
